<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <!--{include file='comm/header.tpl'}-->
    <title>入库单列表</title>
    <!--{include file='comm/comm_cal.tpl'}-->
</head>
<body>

<div class="container">


        <div class="comm_crub">
            <span class="now_crub">入库单列表</span>
        </div>

        <div class="comm_content">

            <div class="search-box" style="background:#f5f5f5;border: 1px solid #c9c9c9">
                <div style="position:relative">
                    <form class="form-inline" id="search_form" onsubmit="return false;">
                        <table>
                            <tbody>
                            <tr>
                                <td>
                                    <span>配送日期：<input type="text" class="form-control input-sm" style="width:110px" value="<!--{$currentDate|default:''}-->" name="send_date" id="send_date"></span>
                                    <span>
                                        配送开始时间：
                                        <select name="send_start_time" id="send_start_time" class="form-control input-sm" style="width:80px;">
                                            <option value="">请选择</option>
                                            <script>
                                                for(var i=0;i < 24;i++){
                                                    if(i <10 ){
                                                        document.write('<option value="0'+ i +':00">' + "0"+i +':00 </option>');
                                                        document.write('<option value="0'+ i +':30">' + "0"+i +':30 </option>');
                                                    }else{
                                                        document.write('<option value="'+ i +':00">'  + i +':00 </option>');
                                                        document.write('<option value="'+ i +':30">'  + i +':30 </option>');
                                                    }
                                                }
                                            </script>

                                        </select>
                                    </span>

                                    <span>
                                        配送结束时间：
                                        <select name="send_end_time" id="send_end_time" class="form-control input-sm" style="width:80px;">
                                            <option value="">请选择</option>
                                            <script>
                                                for(var i=0;i < 24;i++){
                                                    if(i <10 ){
                                                        document.write('<option value="0'+ i +':00">' + "0"+i +':00 </option>');
                                                        document.write('<option value="0'+ i +':30">' + "0"+i +':30 </option>');
                                                    }else{
                                                        document.write('<option value="'+ i +':00">'  + i +':00 </option>');
                                                        document.write('<option value="'+ i +':30">'  + i +':30 </option>');
                                                    }
                                                }
                                            </script>
                                        </select>
                                    </span>

                                    <span>
                                       配送城市：<select id="cityID" name="cityID" class="form-control input-sm" style="width:100px;">
                                            <option value="" selected="">请选择</option>

                                            　　<!--{foreach from=$city item=res}-->
                                            　　 <option  value="<!--{$res['id']}-->"><!--{$res['name']}--></option>
                                            　　<!--{/foreach}-->

                                        </select>
                                    </span>

                                    <span>
                                        配送站：
                                        <select name="distribution_id" id="distribution_id" class="form-control input-sm" style="width:110px;">
                                            <option value="">请选择</option>
                                        </select>
                                    </span>

                                    <span><input type="button" onclick="voucherGoods.search();" class="btn btn-primary" value="查询"></span>
                                    <span><input type="button" onclick="voucherGoods.load();" class="btn btn-warning" value="重置"></span>

                                </td>
                            </tr>
                            </tbody>
                        </table>
                    </form>
                </div>
            </div>

            <div class="panel panel-default"  >

                <div class="panel-heading">入库单商品</div>

                <table class="table table-bordered">
                    <thead>
                    <tr>
                        <th width="100" style="text-align: center;">配送日期</th>
                        <th width="100">站点</th>
                        <th width="100">审核</th>
                        <th width="100">已打印生产单</th>
                        <th width="100">入库</th>
                    </tr>
                    </thead>
                    <tbody id="goods_list"></tbody>
                </table>

            </div>


            <div class="search-box" id = "bill_goods_input" style="display:none;background:white;border: 0px solid #c9c9c9">
                <div style="position:relative">
                    <form class="form-inline" id="item_form" onsubmit="return false;">
                        <table>
                            <tbody>
                            <tr>
                                <td>
                                    <span><span class="red">*</span>条码：<input type="text" class="form-control input-sm" style="width:210px" value="" name="bill_goods_no" id="bill_goods_no" placeholder="请输入订单商品流水号,并按回车键"></span>
                                    <span>累计扫描数量：<input type="text" class="form-control input-sm" style="width:180px" value="0" readonly name="lineCount" id="lineCount" ></span>
                                    <span>质检人：<input type="text" class="form-control input-sm" style="width:180px" value="<!--{$voucher_operator}-->" readonly name="voucher_operator" id="voucher_operator" ></span>
                                </td>
                            </tr>
                            </tbody>
                        </table>
                    </form>
                </div>
            </div>


            <div class="panel panel-default" id="bill_goods_voucher" style="display:none;" >
                <div class="panel-heading">待录入商品</div>
                <table class="table table-bordered">
                    <thead>
                    <tr>
                        <th width="180" style="text-align: center;">商品SKU</th>
                        <th width="140" style="text-align: center;">流水号</th>
                        <th width="*">品名</th>
                        <th width="140">配送站</th>
                        <th width="130" style="text-align: center;">配送日期</th>
                        <th width="120" style="text-align: center;">配送开始时间</th>
                        <th width="120" style="text-align: center;">配送结束时间</th>
                    </tr>
                    </thead>
                    <tbody id="goods_info"></tbody>
                </table>

            </div>

        </div>


</div>

<script type="text/javascript">

    var voucherGoods = {

        bill_goods_no:'',//订单生产流水号

        //查询生成入库单信息
        search: function() {
            $("#goods_list").html('');
            var send_date = $("#send_date").val();
            if(send_date == ""){
                E.alert("配送日期不能为空");
            }
            var formValues = E.getFormValues("search_form");

            E.ajax_post({
                url: "/invokingAjax-backend/wms/voucherGoods.ajax?operFlg=1",
                dataType: "json",
                data:{formValues:formValues},
                call: "voucherGoods.addLineCallBack" //根据条码获取商品信息成功回调函数
            });

        },

        //根据条码获取商品信息成功回调
        addLineCallBack: function (response){

            if (response.code == 200) {
                var data = response.data;//返回入库单数组
                var billGoodsNum = data.length;
                for(var i=0;i<billGoodsNum;i++){
                    var html = '<tr class = "trData" id="goods_line_' + data[i].distribution_id + '">';
                    html += '<td style="text-align: center;">' + data[i].send_date + '</td>';
                    html += '<td>' + data[i].distribution_name + '</td>';
                    html += '<td>' + data[i].bill_goods_num + '</td>';
                    html += '<td>' + data[i].print_num + '</td>';
                    html += '<td>' + data[i].voucher_num + '</td>';
                    html += '</tr>';
                    $('#goods_list').prepend( html );
                }

                $('#bill_goods_input').show();//订单生产流水号部分显示
                $('#bill_goods_voucher').show();//待录入商品信息部分显示
                $('#bill_goods_no').val('').focus();


            } else {

                E.alert(response.message);

            }

        },

        searchBillGoodsInfo:function( bill_goods_no ){

            var formValues = E.getFormValues("search_form");
            E.ajax_post({
                url: "/invokingAjax-backend/wms/voucherGoods.ajax?operFlg=2",
                dataType: "json",
                data:{formValues:formValues,bill_goods_no:bill_goods_no},
                call: "voucherGoods.infoAddLineCallBack"
            });
        },


        //根据条码获取商品信息成功回调
        infoAddLineCallBack: function ( response ){

            if (response.code == 200) { //与头查询条件匹配
                var data = response.data;//返回入库单数组
                var html = '<tr class = "trData" id="goods_line_' + data[0].bill_goods_no + '">';
                html += '<td style="text-align: center;">' + data[0].product_code + '</td>';
                html += '<td style="text-align: center;">' + data[0].bill_goods_no + '</td>';
                html += '<td>' + data[0].goods_name + '</td>';
                html += '<td>' + data[0].distribution_name + '</td>';
                html += '<td style="text-align: center; ">' + data[0].send_date + '</td>';
                html += '<td style="text-align: center;">' + data[0].send_start_time + '</td>';
                html += '<td style="text-align: center;">' + data[0].send_end_time + '</td>';
                html += '</tr>';
                $('#goods_info').prepend( html );
                $('#goods_line_'+data[0].distribution_id).find('td').eq(4).html(parseInt($('#goods_line_'+data[0].distribution_id).find('td').eq(4).html()) +1);
                $('#lineCount').val(parseInt($('#lineCount').val()) + 1);
                $('#goods_line_'+data[0].bill_goods_no).css('background-color','#00ff00');
                E.alert('入库成功',2);
                $('#bill_goods_no').val('').focus();

            } else if( response.code == 201 ){ //与头查询条件不匹配
                var data = response.data;//返回入库单数组
                voucherGoods.bill_goods_no = data[0].bill_goods_no;
                var html = '<tr class = "trData" id="goods_line_' + data[0].bill_goods_no + '">';
                html += '<td style="text-align: center;">' + data[0].product_code + '</td>';
                html += '<td style="text-align: center;">' + data[0].bill_goods_no + '</td>';
                html += '<td>' + data[0].goods_name + '</td>';
                html += '<td>' + data[0].distribution_name + '</td>';
                html += '<td style="text-align: center; ">' + data[0].send_date + '</td>';
                html += '<td style="text-align: center;">' + data[0].send_start_time + '</td>';
                html += '<td style="text-align: center;">' + data[0].send_end_time + '</td>';
                html += '</tr>';
                $('#goods_info').prepend( html );
                $('#goods_line_'+data[0].bill_goods_no).find('td').css('color','red');
                E.confirm('扫描的商品与选择的查询条件不符合，是否继续扫描？','voucherGoods.executeChange','voucherGoods.removeAddLine');

            } else {

                E.alert(response.message);
                $('#bill_goods_no').val('').focus();
            }

        },

        //执行与头查询条件不匹配的订单入库
        executeChange:function(){
            E.ajax_post({
                url: "/invokingAjax-backend/wms/voucherGoods.ajax?operFlg=3",
                dataType: "json",
                data:{bill_goods_no:voucherGoods.bill_goods_no},
                call: "voucherGoods.neqCallBack"
            });
        },


        //与头部查询条件不匹配成功回调
        neqCallBack: function ( response ){

            if (response.code == 200) { //与头查询条件匹配

                $('#lineCount').val(parseInt($('#lineCount').val()) + 1);
                $('#goods_line_'+response.data).css('background-color','#00ff00');
                $('#bill_goods_no').val('').focus();
            } else {

                E.alert(response.message);

            }

        },


        //取消操作
        removeAddLine:function(){
            $('#goods_line_'+voucherGoods.bill_goods_no).remove();
            $('#bill_goods_no').val('').focus();
        },

        //重新加载
        load:function(){
            E.refresh();
            $('#bill_goods_input').hide();//订单生产流水号部分隐藏
            $('#bill_goods_voucher').hide();//待录入商品信息部分隐藏
        }

    };

    //订单流水号回车事件
    $("#bill_goods_no").keydown(function(e){
        if(e.keyCode == 13){
            var bill_goods_no = $.trim($("#bill_goods_no").val());
            if(bill_goods_no == ''){
                global_focus = 'bill_no';
                E.alert('请输入订单商品流水号');
                return false;
            }else{
                voucherGoods.searchBillGoodsInfo( bill_goods_no );
            }
        }
    });

    //日期控件JS
    $('#send_date').datetimepicker();

    //城市=>配送站二级下拉菜单
    $("#cityID").change(function(){
        var value = $(this).val();
        if(value == false){
            html ='<option value="">请选择</option>';
            $("#distribution_id").html(html);
            return;
        }
        $.ajax({
            type:"post",
            url:"/invokingAjax-backend/production/productionSearch.ajax?operFlg=2",
            dataType:"json",
            data:"cityID="+value,
            success:function(res){
                if( res.code == 200 ){
                    var html;
                    for(var i=0;i<res.data.length;i++){
                        var data = res['data'][i];
                        html +="<option value="+data.id+">"+data.name+"</option>";
                    };
                    $("#distribution_id").html(html);
                }
            }
        });
    });
</script>

</body>
</html>